# Copyright (c) 2019 Presto Labs Pte. Ltd.
# Author: jaewon

from coin.base.param_util import to_list
from coin.feed.fastfeed.proto_feed_handler import create_proto_feed_handler


class ProtoFeedAdapter:
  def __init__(self, book_reset_callback):
    self._handlers = {}
    self._book_reset_callbacks = to_list(book_reset_callback)

  def on_book_reset(self, sub_req, underlying_feed_handler):
    handler = create_proto_feed_handler(sub_req, underlying_feed_handler)
    self._handlers[sub_req] = handler
    for callback in self._book_reset_callbacks:
      callback(sub_req, handler)
